// 请求通用方法
import apiMixin from '@/mixin/apiMixin';
import utils from '@/utils/index';
import env from '@/config/env';
export default {
    mixins: [apiMixin],
    data() {
        return {
            authorized_key:  utils.handleLocalStorage.get('authorized_key'),
			baseUrl: env.baseUrl,
            loading: false,
            appList: [],
            h5List: [],
            // app
            banner: [],
            h5Banner: [],
            appNav: [],
            h5Nav: [],
            home_app: [],
            app_sigin: [],
        }
    },
    mounted() {
        this.getHomePicShowApi();
    },
    methods: {
        getHomePicShowApi() {
            let _self = this;
            this.comResquest(this.request.getHomePicShow,(res)=>{
                console.log(res);
                let { app,banner,h5,banner_h5, nav_app, nav_h5, home_app,app_sigin } = res;
                _self.appList = app;
                _self.banner = banner;
                _self.h5Banner = banner_h5;
                _self.h5List = h5;
                _self.h5Nav = nav_h5;
                _self.appNav = nav_app;
                _self.home_app = home_app;
                _self.app_sigin = app_sigin;
            },{
                load: true,
            });
        },
        editHomePiceApi() {
            let _self = this;
            let resPar = {
                load: true,
                app: this.appList,
                banner_h5: this.h5Banner,
                banner: this.banner,
                h5: this.h5List,
                h5Nav: this.h5Nav,
                appNav: this.appNav,
                home_app: this.home_app,
                app_sigin: this.app_sigin,
            };
            this.comResquest(this.request.editHomePice,(res)=>{
                console.log(res);
                _self.$message.success("保存成功");
            },resPar);
        },
        isShowImg(imgUrl) {
            if (!imgUrl) {
                return '../../../../static/img/rotation.png';
            }
            return imgUrl;
        },
        createBid() {
            let prefix = utils.createUploadPrefix('Task');
            let bid = prefix + '-' +  utils.createBidFn();
            return  bid;
        },
        h5ImgUpload(res,h5Index){
            let { code,data } = res;
            if ( Number(code) === 0  ) {
                let img = data.url;
                this.$set(this.h5List,h5Index,{
                    ...this.h5List[h5Index],
                    img
                });
            }
        },
        appImgUpload(res,appIndex){
            let { code,data } = res;
            if ( Number(code) === 0  ) {
                let img = data.url;
                this.$set(this.appList,appIndex,{
                    ...this.appList[appIndex],
                    img
                });
            }
        },
        appHomeImgUpload(res,appIndex){
            let { code,data } = res;
            if ( Number(code) === 0  ) {
                let img = data.url;
                this.$set(this.home_app,appIndex,{
                    ...this.home_app[appIndex],
                    img
                });
            }
        },
        appHomeFloatUpload(res,appIndex){
            let { code,data } = res;
            if ( Number(code) === 0  ) {
                let img = data.url;
                this.$set(this.app_sigin,appIndex,{
                    ...this.app_sigin[appIndex],
                    img
                });
            }
        },
        h5BannerImgUpload(res,bannerIndex) {
            let { code,data } = res;
            if ( Number(code) === 0  ) {
                let img = data.url;
                this.$set(this.h5Banner,bannerIndex,{
                    ...this.h5Banner[bannerIndex],
                    img
                });
            }
        },
        bannerImgUpload(res,bannerIndex){
            let { code,data } = res;
            if ( Number(code) === 0  ) {
                let img = data.url;
                this.$set(this.banner,bannerIndex,{
                    ...this.banner[bannerIndex],
                    img
                });
            }
        },

        h5NavImgUpload(res,index) {
            let { code,data } = res;
            if ( Number(code) === 0  ) {
                let img = data.url;
                this.$set(this.h5Nav,index,{
                    ...this.h5Nav[index],
                    img
                });
            }
        },
        appNavImgUpload(res,index){
            let { code,data } = res;
            if ( Number(code) === 0  ) {
                let img = data.url;
                this.$set(this.appNav,index,{
                    ...this.appNav[index],
                    img
                });
            }
        },
        handleReset(index,type) {
            let curHand = {};
            if (type === 'app') {
                curHand =  JSON.parse(JSON.stringify(this.appList[index]));
                curHand.img = '';
                curHand.url = '';
                this.$set(this.appList,index,curHand);
            }
            if (type === 'h5'){
                curHand = JSON.parse(JSON.stringify(this.h5List[index]));
                curHand.img = '';
                curHand.url = '';
                this.$set(this.h5List,index,curHand);
            }
            if (type === 'home_app') {
                curHand =  JSON.parse(JSON.stringify(this.home_app[index]));
                curHand.img = '';
                curHand.url = '';
                this.$set(this.home_app,index,curHand);
            }
        }
    },
}
